/**
 * RegisterDAO class.
 */
package pits.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import pits.form.RegisterForm;
import pits.util.Constants;

/**
 * @author ltd
 * 
 */
public class RegisterDAO {
	public boolean checkUsername(String username) {
		String query = Constants.BLANK_VALUE;
		Connection conn = null;
		PreparedStatement pStat = null;
		ResultSet rs = null;

		try {
			query = "select * " + "from user " + "where UserName=? and isDeleted=0";
			conn = pits.util.Connection.getConnection();
			pStat = conn.prepareStatement(query);
			pStat.setString(1, username);
			rs = pStat.executeQuery();
			while (rs.next()) {
				return true;
			}
		} catch (Exception sqlEx) {
			new pits.util.Logger().write(sqlEx.toString());
		} finally {
			try {
				rs.close();
				pStat.close();
				conn.close();
			} catch (SQLException sqlEx) {
				new pits.util.Logger().write(sqlEx.toString());
			}
		}

		return false;
	}

	public boolean register(RegisterForm form) {
		boolean rs = false;
		String query = Constants.BLANK_VALUE;
		Connection conn = null;
		PreparedStatement pStat = null;

		try {
			query = "";
			conn = pits.util.Connection.getConnection();
			pStat = conn.prepareStatement(query);
			rs = pStat.execute();
		} catch (Exception sqlEx) {
			new pits.util.Logger().write(sqlEx.toString());
		} finally {
			try {
				pStat.close();
				conn.close();
			} catch (SQLException sqlEx) {
				new pits.util.Logger().write(sqlEx.toString());
			}
		}

		return rs;
	}
}
